#include "Callback.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRRect.h"
#include "util/DT.h"
#include "util/EventQueue.h"
#include "SimpleCanvasRoot.h"
#include "widget/TextView.h"
#include "widget/TestView.h"
#include "drawable/ImageDrawable.h"
#include "Theme.h"
#include <Theme.cpp>

using namespace yzrilyzr_simplecanvas;
using namespace yzrilyzr_util;
SimpleCanvasRoot scRoot;
EventQueue eventQueue;
struct AppSystemEvent{
	int type;
};

std::shared_ptr<ImageDrawable> imgd;
DT dt;
int index111=0;

void onCreateApp(){
	eventQueue.subscribe<AppSystemEvent>([](const AppSystemEvent & ev){
		if(ev.type == 69663){
		#ifdef _WIN32
			char * a=(char *)99;
			std::cout << *((int *)a) << std::endl;
		#endif // _WIN32
		}
	});
	if(true){
		eventQueue.publishDelayed(AppSystemEvent{123}, std::chrono::milliseconds(3000));
	}
	Theme::loadTypeface(u8"D:/Projects/Java/libs/SimpleCanvas/testRun/font.ttf");
	std::shared_ptr<TextView> v=std::make_shared<TextView>();
	std::shared_ptr<TestView> v2=std::make_shared<TestView>();
	v->setText(u8"Test Text\ntest 娃儿1234\ngweovntiwehcweiormciowmcrjworthv\ngweovntiwehcweiormciowmcrjworthv gweovntiwehcwei ormciowmcrjworthv\ngweovntiwehcweiormciowmcrjworthv");
	imgd=std::make_shared<ImageDrawable>(u8"C:/Users/yzrilyzr/Pictures/01700050483666.png");
	imgd->setScaleMode(ImageScaleMode::CENTER);
	v->setBackground(imgd);
	scRoot.setBaseView(v);
}
void onWindowSizeChange(int32_t w, int32_t h){
	scRoot.changeSize(w, h);
}
void onDraw(SkCanvas & canvas){
	scRoot.draw(canvas);
	float ldt=dt.getDeltaTime();
	imgd->setScaleMode((ImageScaleMode)(index111));

	if(ldt > 0){
		index111++;
		if(index111 > 7)index111=0;
		dt.reset();
	}
}